Skip to content

fix(salary): dedicated migration + tests for salary models (W2-B-038) - #947

Merged
likableai merged 1 commit into
Pi-Defi-world:devfrom
Raven062:fix/W2-B-038-salary-models-migration-tests
Sep 1, 2026
Merged

fix(salary): dedicated migration + tests for salary models (W2-B-038)#947
likableai merged 1 commit into
Pi-Defi-world:devfrom
Raven062:fix/W2-B-038-salary-models-migration-tests

Conversation

@Raven062

@Raven062 Raven062 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes W2-B-038salaryBatch / salaryItem / salarySchedule models missing in salaryService, causing 13 TS2339 errors and making the entire payroll module non-functional.

Root cause

The Prisma schema already defined all three models correctly. However, the three salary tables (salary_batches, salary_items, salary_schedules) were bundled into the large 20260423111042_init migration alongside many unrelated changes, with no dedicated migration of their own. This means:

  • Fresh environments or environments that applied only a subset of migrations have no clearly-auditable path to create the salary tables.
  • @prisma/client couldn't resolve the types, causing TS2339 on all 13 access sites in salaryService.ts.

Changes

prisma/migrations/20260901000000_add_salary_models/migration.sql

Dedicated, idempotent migration for all three salary tables:

  • CREATE TABLE IF NOT EXISTS for salary_batches, salary_items, salary_schedules — column definitions match schema.prisma exactly.
  • CREATE UNIQUE INDEX IF NOT EXISTS / CREATE INDEX IF NOT EXISTS for all indexes.
  • Foreign keys added inside a DO 23899 block that checks pg_constraint first — safe on environments that already ran the init migration.

This follows the same idempotency pattern already used by other migrations in this repo (e.g. 20260825120100_add_user_lockout_fields, 20260423000000_add_organization_id_to_transactions).

tests/salaryService.test.ts — 20 test cases, no real DB

Suite Cases
createSalaryBatch Normal path, idempotency hit, total mismatch → 400, correct total accepted
processSalaryBatch All-success → completed, partial failure → partially_completed, all-failed, resume support (skip completed items), rejected transfer writes via $transaction, batch-not-found guard, already-completed guard
getSalaryBatches Pagination params forwarded, _count.items included
createSalarySchedule Normal path + nextRunAt from dateUtils, invalid cron → 400, empty cron → 400, currency default
triggerSchedule Fires createSalaryBatch, updates lastRunAt/nextRunAt, skips non-active schedules, uses 60 s offset for non-daily cron

Acceptance

  • prisma migrate deploy succeeds on fresh and existing environments (idempotent SQL)
  • Salary service tests pass

closes #748

…038)

W2-B-038 — salaryBatch / salaryItem / salarySchedule models missing

Root cause
----------
The Prisma schema already defined SalaryBatch, SalaryItem, and SalarySchedule,
but the three salary tables were bundled into the large 20260423111042_init
migration without a standalone, clearly-named migration of their own.
Environments that ran a subset of migrations (or fresh deploys that need an
audit trail of when each feature was added) had no dedicated migration to apply,
causing prisma migrate deploy to leave the tables absent and TypeScript to
report TS2339 on every prisma.salaryBatch / salaryItem / salarySchedule access
(13 sites in salaryService.ts).

Changes
-------
prisma/migrations/20260901000000_add_salary_models/migration.sql
  - Creates salary_batches, salary_items, salary_schedules with full column
    definitions matching schema.prisma exactly.
  - All CREATE TABLE statements use IF NOT EXISTS so the migration is safe to
    run on environments that already have the tables from the init migration.
  - Unique and regular indexes use CREATE INDEX IF NOT EXISTS.
  - Foreign keys are added inside a DO dollar block that checks pg_constraint
    first, making them idempotent too.

tests/salaryService.test.ts (20 test cases, no real DB)
  - createSalaryBatch: normal path, idempotency hit, total mismatch (400),
    correct total accepted
  - processSalaryBatch: all-success (completed), partial failure
    (partially_completed), all-failed, resume support (skip completed items),
    rejected transfer writes via dollar-transaction, batch-not-found guard,
    already-completed guard
  - getSalaryBatches: pagination params forwarded, includes count.items
  - createSalarySchedule: normal path + nextRunAt from dateUtils, invalid
    cron (400), empty cron (400), currency default
  - triggerSchedule: fires createSalaryBatch, updates lastRunAt/nextRunAt,
    skips non-active schedules, uses 60s offset for non-daily cron
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 3227a274-4301-4cec-9b8f-0be05f4ef3e0


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@Raven062 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@likableai
likableai merged commit 01c5e8f into Pi-Defi-world:dev Sep 1, 2026
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

W2-B-038 - salaryBatch / salaryItem / salarySchedule models missing in salaryService

2 participants